import logging.handlers
import os

log_path = "./Log" + os.sep + "hmx.log"


def log_config():
    """初始化日志配置"""
    logger = logging.getLogger()

    logger.setLevel(logging.INFO)

    sh = logging.StreamHandler()

    trf = logging.handlers.TimedRotatingFileHandler(filename=log_path, when="midnight", interval=1, backupCount=7,
                                                    encoding="utf-8")
    fmt = "%(asctime)s %(levelname)s [%(filename)s(%(funcName)s:%(lineno)d)] - %(message)s"

    formatter = logging.Formatter(fmt)

    sh.setFormatter(formatter)

    trf.setFormatter(formatter)

    logger.addHandler(sh)

    logger.addHandler(trf)


